/*
   Copyright (c) 2019 Shanghai Xuanzi Technology Co. Ltd https://xuanzi.ltd
   XZMindMap is licensed under the Mulan PSL v1.
   You can use this software according to the terms and conditions of the Mulan PSL v1.
   You may obtain a copy of Mulan PSL v1 at:
      http://license.coscl.org.cn/MulanPSL
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
   PURPOSE.
   See the Mulan PSL v1 for more details.

*/

package xuanzi.openmind.nodes;

import xuanzi.commons.graphics.PointF;

public class ShapeUtils {

	
	public static void main(String[] args) {
		PointF aa = new PointF(-100,-200);

		PointF bb = new PointF(100,100);

		PointF cc = new PointF(100,-200);
		PointF dd = new PointF(-100,100);
		PointF s = intersectPoint(aa,bb,cc,dd);
		System.out.println(s);
	}
	
	public ShapeUtils() {
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * 两直线相交点
	 * @param a
	 * @param b
	 * @param c
	 * @param d
	 * @return
	 */
	public static PointF intersectPoint(PointF a, PointF b, PointF c, PointF d) {   
		double deita = (b.x - a.x) * (c.y - d.y) - (d.x - c.x) * (a.y - b.y);
		float x = (c.y * d.x - c.x * d.y) * (b.x - a.x)
		- (a.y * b.x - a.x * b.y) * (d.x - c.x);
		x /= deita;
		float y = (a.y * b.x - a.x * b.y) * (c.y - d.y)
		- (c.y * d.x - c.x * d.y) * (a.y - b.y);
		y /= deita;
		return new PointF(x, y);
	}
	
 

}
